#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;

int main() {
    int n, q; cin >> n >> q;
    while (q--) {
        string s; cin >> s;
        int res = 1;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == 'L') res = res * 2 - 1;
            else res = res * 2;
        }
        cout << res << endl;
    }
    return 0;
}